import re

CONDITIONS = [
    ("byr", lambda x: 1920 <= int(x) <= 2002),
    ("iyr", lambda x: 2010 <= int(x) <= 2020),
    ("eyr", lambda x: 2020 <= int(x) <= 2030),
    (
        "hgt",
        lambda x: (x[-2:] == "cm" and 150 <= int(x[:-2]) <= 193)
        or (x[-2:] == "in" and 59 <= int(x[:-2]) <= 76),
    ),
    ("hcl", lambda x: re.fullmatch(r'#[0-9a-f]{6}', x)),
    ("ecl", lambda x: x in ("amb", "blu", "brn", "gry", "grn", "hzl", "oth")),
    ("pid", lambda x: re.fullmatch(r"[0-9]{9}", x)),
]

with open('input.txt') as file:
    count = 0

    for passport_lines in file.read().split('\n\n'):
        passport = {}

        for parts in passport_lines.split():
            key, value = parts.split(':')
            passport[key] = value

        valid = True
        for (key, condition) in CONDITIONS:
            if not( key in passport and condition(passport[key]) ):
                valid = False
                break
        
        if valid:
            count += 1

    print(count)    
        